package com.itany.corejava.code11_内部类;

import com.itany.corejava.util.SortCompareInterface;
import com.itany.corejava.util.SortUtil;

import java.util.Arrays;

/**
 * @author 石小俊
 * @version 1.0
 * @date 2023年03月20日 16:58
 */
public class Test05_练习 {
    public static void main(String[] args) {
        // 对数组进行排序
        // 如果是数值型,则按照自然顺序的大小排序
        // 如果是字符串,则按照字符串的长度进行排序
        Integer[] numbers = {1, 11, 3, 34, 22, 21};
        SortUtil.sort(numbers, new SortCompareInterface<Integer>() {
            @Override
            public int compareTo(Integer t1, Integer t2) {
                // 降序
                return t2 - t1;
            }
        });
        System.out.println(Arrays.toString(numbers));
        String[] names = {"admin", "jack", "tom", "ab", "d", "alice"};
        SortUtil.sort(names, new SortCompareInterface<String>() {
            @Override
            public int compareTo(String t1, String t2) {
                // 升序
                return t1.length() - t2.length();
            }
        });
        System.out.println(Arrays.toString(names));
    }
}
